FROM nvidia/cuda:13.0.1-cudnn-devel-ubuntu24.04

USER root

ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Shanghai
# 设置中文环境
ENV LANG=zh_CN.UTF-8
ENV LANGUAGE=zh_CN:zh
ENV LC_ALL=zh_CN.UTF-8
# 将 Miniconda 加入 PATH
ENV PATH="/root/miniconda3/bin:${PATH}"

# 一次性完成系统配置、依赖安装和清理
RUN \
    # 1. 配置阿里云 APT 源
    echo "Types: deb" > /etc/apt/sources.list.d/ubuntu.sources && \
    echo "URIs: https://mirrors.aliyun.com/ubuntu/" >> /etc/apt/sources.list.d/ubuntu.sources && \
    echo "Suites: noble noble-updates noble-backports noble-security" >> /etc/apt/sources.list.d/ubuntu.sources && \
    echo "Components: main restricted universe multiverse" >> /etc/apt/sources.list.d/ubuntu.sources && \
    echo "Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg" >> /etc/apt/sources.list.d/ubuntu.sources && \
    \
    # 2. 安装所有依赖
    apt-get update && \
    apt-get upgrade -y && \
    echo "tzdata tzdata/Areas select Asia" | debconf-set-selections && \
    echo "tzdata tzdata/Zones/Asia select Shanghai" | debconf-set-selections && \
    apt-get install -y --no-install-recommends \
    # 基础环境和工具
    tzdata \
    build-essential vim git cmake ninja-build wget curl \
    llvm clang clangd clang-format \
    btop neofetch \
    openssh-server \
    locales language-pack-zh-hans \
    # C++ 核心库
    libboost-all-dev libeigen3-dev libfmt-dev libgoogle-glog-dev libopencv-dev \
    # C++ 增强库
    libgtest-dev libbenchmark-dev nlohmann-json3-dev libprotobuf-dev protobuf-compiler \
    libyaml-cpp-dev libcurl4-openssl-dev libgrpc-dev libtbb-dev \
    # 系统、调试与终端工具
    gdb valgrind strace ltrace git-lfs net-tools dnsutils tmux ripgrep fd-find && \
    \
    # 3. 配置系统
    echo "root:123" | chpasswd && \
    sed -i 's/#\?PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config && \
    sed -i 's/#\?PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config && \
    sed -i -e 's/# zh_CN.UTF-8 UTF-8/zh_CN.UTF-8 UTF-8/' /etc/locale.gen && \
    locale-gen && \
    rm /bin/sh && ln -s /bin/bash /bin/sh && \
    git lfs install --system && \
    \
    # 4. 清理 APT 缓存
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# 安装并配置 Miniconda
RUN \
    # 1. 下载并安装
    wget -q https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py313_25.7.0-2-Linux-x86_64.sh -O Miniconda3.sh && \
    bash Miniconda3.sh -b -p /root/miniconda3 && \
    rm Miniconda3.sh && \
    \
    # 2. 初始化 Conda 并配置 pip 源
    conda init bash && \
    /root/miniconda3/bin/pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/

EXPOSE 22
WORKDIR /root

# 启动容器时自动开启SSH服务并保持运行
CMD ["/bin/bash", "-c", "service ssh start && tail -f /dev/null"]